package router

import (
	"common/config"
	"common/database"
	"common/logs"
	"common/rpc"
	"core/repo"
	"gate/api"
	"gate/auth"
	admin "gate/router/admin"
	v1 "gate/router/v1"

	"github.com/gin-gonic/gin"
)

func RegisterRouter() *gin.Engine {
	if config.Conf.Log.Level == "DEBUG" {
		gin.SetMode(gin.DebugMode)
	} else {
		gin.SetMode(gin.ReleaseMode)
	}
	rpc.Init()
	//
	repo := repo.New()
	logs.Error("mysql start")
	repo.Mysql = database.NewMysql()
	r := gin.Default()
	r.Use(auth.Cors())
	userHandler := api.NewUserHandle()
	r.POST("/register", userHandler.Register)

	// 注册游戏模块的路由
	admin.NewGameRouter(r, repo)
	v1.NewWxApiRouter(r, repo)
	return r
}
